package cn.ffcs.unm.speWorkType.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringEscapeUtils;
import org.springframework.stereotype.Repository;

import cn.ffcs.unm.speWorkType.dao.SpeWorkTypeDao;
import cn.ffcs.unm.speWorkType.model.SpeWorkType;
import cn.ffcs.uom.common.dao.BaseDaoImpl;
import cn.ffcs.uom.common.util.StrUtil;
import cn.ffcs.uom.common.vo.PageInfo;

@Repository("speWorkTypeDao")
public class SpeWorkTypeDaoImpl extends BaseDaoImpl implements SpeWorkTypeDao {

	@Override
	public PageInfo queryPageInfoBySpeWorkType(SpeWorkType speWorkType,
			int currentPage, int pageSize) {
		StringBuilder sb = new StringBuilder();
		sb.append(" select  distinct ja3.name  staffName,ja3.code code, ja1.MONTH_ID  monthId,ja1.UNIT_ID  单位编码,ja1.PK_PSNDOC_SUB  pkPsndocSub, ");
		sb.append(" ja1.ENDDATE  结束日期,ja1.GLBDEF3  glbdef3,ja1.GLBDEF4  glbdef4,ja1.LASTFLAG  最近记录标志, ");
		sb.append(" ja1.MODIFIEDTIME  修改时间,ja1.RECORDNUM  记录序号,ja1.BEGINDATE  开始日期,ja1.CREATIONTIME  创建时间, ");
		sb.append(" ja1.TS  时间戳,ja1.DR	删除标示,ja1.GLBDEF5  glbdef5  ");
		sb.append(" from LDAPM_MPW_HI_PSNDOC_GLBDEF5 ja1 ,LDAPM_MPW_bd_psndoc ja3 ");
		sb.append("  where JA1.pk_psndoc=JA3.pk_psndoc and JA1.MONTH_ID=JA3.MONTH_ID");
		List<Object> params = new ArrayList<Object>();
		if (null != speWorkType) {
			if (!StrUtil.isEmpty(speWorkType.getMonthId())) {
				sb.append(" AND ja1.MONTH_ID = ? ");
				params.add(speWorkType.getMonthId());
			}
			if (!StrUtil.isEmpty(speWorkType.getStaffName())) {
				sb.append(" AND ja3.name LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(speWorkType.getStaffName())
						+ "%");
			}
			if (!StrUtil.isEmpty(speWorkType.getCode())) {
				sb.append(" AND ja3.code LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(speWorkType.getCode())
						+ "%");
			}
		}
		return this.jdbcFindPageInfo(sb.toString(), params, currentPage,
				pageSize, SpeWorkType.class);
	}
}
